home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 2 / ETO Development Tools 2.iso / Tools - Objects / MacApp / MacApp CD Release / MacApp 2.0.1 (Many Libraries) / Libraries / UMacApp.TControls.p < prev    next >
Encoding:
Text File  |  1990-10-25  |  37.0 KB  |  1,537 lines  |  [TEXT/MPS ]

  1. {$P}
  2. {[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n-]}
  3. {UMacApp.TControls.p}
  4. {Copyright © 1987-1990 by Apple Computer Inc.  All rights reserved.}
  5.  
  6. {--------------------------------------------------------------------------------------------------}
  7. {$S MAControlRes}
  8.  
  9. PROCEDURE ActionProcForTScrollBar(aCMgrControl: ControlHandle;
  10.                          partCode: INTEGER);
  11.  
  12.     VAR
  13.         aScrollBar:         TScrollBar;
  14.  
  15.     BEGIN
  16.     aScrollBar := TScrollBar(GetCRefCon(aCMgrControl));
  17.     FailNil(aScrollBar);    { What else you gonna' do? }
  18.  
  19.     aScrollBar.ActionProc(partCode);
  20.     END;
  21.  
  22. {--------------------------------------------------------------------------------------------------}
  23. {$S MASelCommand}
  24.  
  25. PROCEDURE TControlTracker.IControlTracker(theControl: TControl);
  26.  
  27.     BEGIN
  28.     INoChangesCommand(cTrackingControl, NIL, theControl, theControl.GetScroller(TRUE));
  29.     {$IFC qDebug}
  30.     IF theControl = NIL THEN
  31.         ProgramBreak('Control passed to IControlTracker can''t be NIL.');
  32.     {$ENDC}
  33.     fControl := theControl;
  34.     fTrackNonMovement := TRUE;
  35.     fViewConstrain := FALSE;
  36.     END;
  37.  
  38. {--------------------------------------------------------------------------------------------------}
  39. {$S MAFields}
  40.  
  41. PROCEDURE TControlTracker.Fields(PROCEDURE DoToField(fieldName: Str255;
  42.                                                      fieldAddr: Ptr;
  43.                                                      fieldType: INTEGER)); OVERRIDE;
  44.  
  45.     BEGIN
  46.     DoToField('TControlTracker', NIL, bClass);
  47.     DoToField('fControl', @fControl, bObject);
  48.     INHERITED Fields(DoToField);
  49.     END;
  50.  
  51. {--------------------------------------------------------------------------------------------------}
  52. {$S MAOpen}
  53.  
  54. PROCEDURE TControl.IControl(itsSuperView: TView;
  55.                             itsLocation, itsSize: VPoint;
  56.                             itsHSizeDet, itsVSizeDet: SizeDeterminer);
  57.     VAR
  58.         itsDocument: TDocument;
  59.  
  60.  
  61.     BEGIN
  62.     {$IFC qDebug}
  63.     WITH itsSize DO
  64.         IF (h > kMaxCoord) | (v > kMaxCoord) THEN
  65.             ProgramBreak(ConcatNumber('The size in pixels of a TControl cannot exceed ', kMaxCoord));
  66.     {$ENDC}
  67.  
  68.  
  69.     { !!! Really need to have itsDocument come in through the parameter list (post 2.0)
  70.     Make best guess for now. }
  71.     IF itsSuperView <> NIL THEN
  72.         itsDocument := itsSuperView.fDocument
  73.     ELSE
  74.         itsDocument := NIL;
  75.  
  76.     fTextStyle := gSystemStyle;    { Put in safe state }
  77.     IView(itsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  78.     fDefChoice := mOKHit;
  79.     fHilite := FALSE;
  80.     fDimmed := FALSE;
  81.     fSizeable := TRUE;
  82.     fAdornment := [];
  83.     fPenSize := Point($00010001);
  84.     fInset := gZeroRect;
  85.     fTextStyle := gSystemStyle;
  86.     fDismissesDialog := FALSE;
  87.     END;
  88.  
  89. {--------------------------------------------------------------------------------------------------}
  90. {$S MAOpen}
  91.  
  92. PROCEDURE TControl.IRes(itsDocument: TDocument;
  93.                         itsSuperView: TView;
  94.                         VAR itsParams: Ptr);
  95.  
  96.     VAR
  97.         aTextStyle:         TextStyle;
  98.  
  99.     BEGIN
  100.     fTextStyle := gSystemStyle;    { Put in safe state }
  101.  
  102.     INHERITED IRes(itsDocument, itsSuperView, itsParams);
  103.  
  104.     WITH ControlTemplatePtr(itsParams)^ DO
  105.         BEGIN
  106.         fDefChoice := mOKHit;                            {??? This seems questionable}
  107.         fAdornment := itsAdornment;
  108.         fSizeable := isSizable;
  109.         fHilite := isHilited;
  110.         fDimmed := isDimmed;
  111.         fDismissesDialog := canDismiss;
  112.         fInset := itsInset;
  113.         fPenSize := itsPenSize;
  114.         SetTextStyle(aTextStyle, GetFontNum(itsFontName), itsTextFace, itsTextSize, itsTextColor);
  115.         fTextStyle := aTextStyle;
  116.  
  117.         OffsetPtrWStr(itsParams, SIZEOF(ControlTemplate));
  118.         END;
  119.  
  120.     {$IFC qDebug}    { Any good reason besides TControl??? }
  121.     {$Push} {$H-}
  122.     WITH fSize DO
  123.         IF (h > kMaxCoord) | (v > kMaxCoord) THEN
  124.             ProgramBreak(ConcatNumber('The size in pixels of a TControl cannot exceed ', kMaxCoord));
  125.     {$Pop}
  126.     {$ENDC}
  127.     END;
  128.  
  129. {--------------------------------------------------------------------------------------------------}
  130. {$S MAWriteRes}
  131.  
  132. PROCEDURE TControl.WRes(theResource: ViewRsrcHndl;
  133.                         VAR itsParams: Ptr); OVERRIDE;
  134.  
  135.     VAR
  136.         theSize:            INTEGER;
  137.         theFont:            Str255;
  138.         cnPtr:                ControlTemplatePtr;
  139.  
  140.     BEGIN
  141.     INHERITED WRes(theResource, itsParams);
  142.  
  143.     WITH fTextStyle DO
  144.         BEGIN
  145.         theSize := tsSize;
  146.         {$Push} {$H-}
  147.         GetPortFontInfo(tsFont, theFont, theSize);
  148.         {$Pop}
  149.         END;
  150.  
  151.     cnPtr := ControlTemplatePtr(ExpandPtrWStr(theResource, itsParams, SIZEOF(ControlTemplate),
  152.                                               LENGTH(theFont)));
  153.  
  154.     WITH cnPtr^ DO
  155.         BEGIN
  156.         itsAdornment := fAdornment;
  157.         itsPenSize := fPenSize;
  158.         isSizable := fSizeable;
  159.         isDimmed := fDimmed;
  160.         isHilited := fHilite;
  161.         canDismiss := fDismissesDialog;
  162.         itsInset := fInset;
  163.         WITH fTextStyle DO
  164.             BEGIN
  165.             itsTextFace := tsFace;
  166.             itsTextSize := theSize;
  167.             itsTextColor := tsColor;
  168.             END;
  169.         { itsFontName := theFont; }
  170.         CopyStr255(theFont, PRStr(itsFontName));
  171.         END;
  172.     END;
  173.  
  174. {--------------------------------------------------------------------------------------------------}
  175. {$S MAWriteRes}
  176.  
  177. PROCEDURE TControl.WriteRes(theResource: ViewRsrcHndl;
  178.                             VAR itsParams: Ptr); OVERRIDE;
  179.  
  180.     BEGIN
  181.     gWResSignature := 'cntl'; gWResType := 'TControl';
  182.     WRes(theResource, itsParams);
  183.     END;
  184.  
  185. {--------------------------------------------------------------------------------------------------}
  186. {$S MAControlRes}
  187.  
  188. PROCEDURE TControl.ComputeSize(VAR newSize: VPoint); OVERRIDE;
  189.  
  190.     VAR
  191.         deltaSz:            Point;
  192.  
  193.     BEGIN
  194.     INHERITED ComputeSize(newSize);
  195.     IF NOT fSizeable THEN
  196.         BEGIN                                            { …we need to adjust the bot/right offset }
  197.         WITH deltaSz DO
  198.             BEGIN
  199.             h := newSize.h - fSize.h;                    { Controls cannot be bigger than QD space. }
  200.             v := newSize.v - fSize.v;
  201.             END;
  202.  
  203.         IF Longint(deltaSz) <> 0 THEN                    { If view is going to change size, then… }
  204.         {$Push} {$H-}
  205.             AddPt(deltaSz, fInset.botRight);            { …doesn't change control's actual size }
  206.         {$Pop}
  207.         END;
  208.     END;
  209.  
  210. {--------------------------------------------------------------------------------------------------}
  211. {$S MAControlRes}
  212.  
  213. FUNCTION TControl.ContainsMouse(theMouse: VPoint): BOOLEAN; OVERRIDE;
  214.  
  215.     VAR
  216.         aRect:                Rect;
  217.  
  218.     BEGIN
  219.     ControlArea(aRect);
  220.     ContainsMouse := PtInRect(VPtToPt(theMouse), aRect);
  221.     END;
  222.  
  223. {--------------------------------------------------------------------------------------------------}
  224. {$S MAControlRes}
  225.  
  226. PROCEDURE TControl.ControlArea(VAR theArea: Rect);
  227.  
  228.     BEGIN
  229.     {$Push} {$H-}
  230.     WITH fInset, fSize DO
  231.         SetRect(theArea, left, top, h - right, v - bottom);
  232.     {$Pop}
  233.     IF adnShadow IN fAdornment THEN
  234.         SubPt(fPenSize, theArea.botRight);
  235.     END;
  236.  
  237. {--------------------------------------------------------------------------------------------------}
  238. {$S MAControlRes}
  239.  
  240. PROCEDURE TControl.Dim;
  241.  
  242.     VAR
  243.         area:                Rect;
  244.  
  245.     BEGIN
  246.     {$IFC qDebug}
  247.     AssumeFocused;
  248.     {$ENDC}
  249.  
  250.     ControlArea(area);
  251.     PenPat(gray);
  252.     PenMode(patBic);
  253.     PaintRect(area);
  254.     END;
  255.  
  256. {--------------------------------------------------------------------------------------------------}
  257. {$S MANonRes}
  258.  
  259. PROCEDURE TControl.DimState(state, redraw: BOOLEAN);
  260.  
  261.     BEGIN
  262.     IF state <> fDimmed THEN
  263.         BEGIN
  264.         fDimmed := state;
  265.         IF redraw THEN
  266.             DrawContents;                                { Draw change immediately }
  267.         END;
  268.     END;
  269.  
  270. {--------------------------------------------------------------------------------------------------}
  271. {$S MASelCommand}
  272.  
  273. FUNCTION TControl.DoMouseCommand(VAR theMouse: Point;
  274.                                  VAR info: EventInfo;
  275.                                  VAR hysteresis: Point): TCommand; OVERRIDE;
  276.  
  277.     VAR
  278.         aControlTracker:    TControlTracker;
  279.  
  280.     BEGIN
  281.     NEW(aControlTracker);
  282.     FailNIL(aControlTracker);
  283.     aControlTracker.IControlTracker(SELF);
  284.     DoMouseCommand := aControlTracker;
  285.     END;
  286.  
  287. {--------------------------------------------------------------------------------------------------}
  288. {$S MAControlRes}
  289.  
  290. PROCEDURE TControl.Draw(area: Rect); OVERRIDE;
  291.  
  292.     VAR
  293.         qdExtent:            Rect;
  294.  
  295.     BEGIN
  296.     IF fAdornment <> [] THEN
  297.         BEGIN
  298.         GetQDExtent(qdExtent);
  299.         Adorn(qdExtent, fPenSize, fAdornment);
  300.         END;
  301.     IF fDimmed THEN
  302.         Dim;
  303.     IF fHilite THEN
  304.         Hilite;
  305.  
  306.     INHERITED Draw(area);
  307.     END;
  308.  
  309. {--------------------------------------------------------------------------------------------------}
  310. {$S DlgRes}
  311.  
  312. PROCEDURE TControl.Flash;
  313.  
  314.     VAR
  315.         dontCare:            Longint;
  316.  
  317.     BEGIN
  318.     HiliteState(TRUE, kRedraw);
  319.     Delay(8, dontCare);
  320.     HiliteState(FALSE, kRedraw);
  321.     END;
  322.  
  323. {--------------------------------------------------------------------------------------------------}
  324. {$S MAControlRes}
  325.  
  326. FUNCTION TControl.Focus: BOOLEAN; OVERRIDE;
  327.  
  328.     VAR
  329.         aTextStyle:         TextStyle;
  330.  
  331.     BEGIN
  332.     IF INHERITED Focus THEN
  333.         BEGIN
  334.         aTextStyle := fTextStyle;
  335.         SetPortTextStyle(aTextStyle);
  336.         PenNormal;
  337.         Focus := TRUE;
  338.         END
  339.     ELSE
  340.         Focus := FALSE;
  341.     END;
  342.  
  343. {--------------------------------------------------------------------------------------------------}
  344. {$S MAControlRes}
  345.  
  346. PROCEDURE TControl.Hilite;
  347.  
  348.     VAR
  349.         aRect:                Rect;
  350.  
  351.     BEGIN
  352.     {$IFC qDebug}
  353.     AssumeFocused;
  354.     {$ENDC}
  355.  
  356.     ControlArea(aRect);
  357.     InvertRect(aRect);
  358.     END;
  359.  
  360. {--------------------------------------------------------------------------------------------------}
  361. {$S MANonRes}
  362.  
  363. PROCEDURE TControl.HiliteState(state, redraw: BOOLEAN);
  364.  
  365.     BEGIN
  366.     IF state <> fHilite THEN
  367.         BEGIN
  368.         fHilite := state;
  369.         IF redraw & Focus & IsVisible THEN
  370.             Hilite;
  371.         END;
  372.     END;
  373.  
  374. {--------------------------------------------------------------------------------------------------}
  375. {$S MANonRes}
  376.  
  377. PROCEDURE TControl.Inset(dh, dv: INTEGER;
  378.                          redraw: BOOLEAN);
  379.  
  380.     BEGIN
  381.     IF fSizeable THEN
  382.         BEGIN
  383.         {$Push} {$H-}
  384.         OffsetRect(fInset, dh, dv);
  385.         WITH fSize DO
  386.             Resize(h, v, redraw);
  387.         {$Pop}
  388.         END;
  389.     END;
  390.  
  391. {--------------------------------------------------------------------------------------------------}
  392. {$S MANonRes}
  393.  
  394. PROCEDURE TControl.InstallColor(theColor: RGBColor;
  395.                                 redraw: BOOLEAN);
  396.  
  397.     BEGIN
  398.     fTextStyle.tsColor := theColor;
  399.     IF redraw THEN
  400.         DrawContents;
  401.     END;
  402.  
  403. {--------------------------------------------------------------------------------------------------}
  404. {$S MANonRes}
  405.  
  406. PROCEDURE TControl.InstallTextStyle(theTextStyle: TextStyle;
  407.                                     redraw: BOOLEAN);
  408.  
  409.     BEGIN
  410.     fTextStyle := theTextStyle;
  411.     IF redraw THEN
  412.         DrawContents;
  413.     END;
  414.  
  415. {--------------------------------------------------------------------------------------------------}
  416. {$S MAControlRes}
  417.  
  418. FUNCTION TControl.isDimmed: BOOLEAN;
  419.  
  420.     BEGIN
  421.     isDimmed := fDimmed;
  422.     END;
  423.  
  424. {--------------------------------------------------------------------------------------------------}
  425. {$S MANonRes}
  426.  
  427. PROCEDURE TControl.Resize(width, height: VCoordinate;
  428.                           invalidate: BOOLEAN); OVERRIDE;
  429.  
  430.     BEGIN
  431.  { If we need to invalidate, then invalidate the whole view rather than
  432.   the difference between the old and new size. }
  433.     INHERITED Resize(width, height, invalidate);
  434.     IF invalidate THEN
  435.         ForceRedraw;
  436.     END;
  437.  
  438. {--------------------------------------------------------------------------------------------------}
  439. {$S MANonRes}
  440.  
  441. PROCEDURE TControl.SetInset(newInset: Rect;
  442.                             redraw: BOOLEAN);
  443.  
  444.     BEGIN
  445.     IF fSizeable THEN
  446.         BEGIN
  447.         fInset := newInset;
  448.         WITH fSize DO
  449.             {$Push} {$H-}
  450.             Resize(h, v, redraw);
  451.             {$Pop}
  452.         END;
  453.     END;
  454.  
  455. {--------------------------------------------------------------------------------------------------}
  456. {$S MASelCommand}
  457.  
  458. PROCEDURE TControl.TrackFeedback(anchorPoint, nextPoint: VPoint; turnItOn, mouseDidMove: BOOLEAN);
  459.  
  460.     BEGIN
  461.     END;
  462.  
  463. {--------------------------------------------------------------------------------------------------}
  464. {$S MASelCommand}
  465.  
  466. PROCEDURE TControl.TrackMouse(aTrackPhase: TrackPhase;
  467.                               VAR anchorPoint, previousPoint, nextPoint: VPoint;
  468.                               mouseDidMove: BOOLEAN);
  469.  
  470.     BEGIN
  471.     CASE aTrackPhase OF
  472.         trackPress:
  473.             HiliteState(TRUE, kRedraw);
  474.         trackMove:
  475.             HiliteState(ContainsMouse(nextPoint), kRedraw);
  476.         trackRelease:
  477.             BEGIN
  478.             IF fHilite THEN
  479.                 HiliteState(FALSE, kRedraw);
  480.             IF ContainsMouse(nextPoint) THEN
  481.                 DoChoice(SELF, fDefChoice);
  482.             END;
  483.     END;
  484.     END;
  485.  
  486. {--------------------------------------------------------------------------------------------------}
  487. {$S MAControlRes}
  488.  
  489. FUNCTION TControl.Validate: Longint;
  490.  
  491.     BEGIN
  492.     Validate := noErr;
  493.     END;
  494.  
  495. {--------------------------------------------------------------------------------------------------}
  496. {$S MAFields}
  497.  
  498. PROCEDURE TControl.Fields(PROCEDURE DoToField(fieldName: Str255;
  499.                                               fieldAddr: Ptr;
  500.                                               fieldType: INTEGER)); OVERRIDE;
  501.  
  502.     BEGIN
  503.     DoToField('TControl', NIL, bClass);
  504.     DoToField('fDefChoice', @fDefChoice, bInteger);
  505.     DoToField('fHilite', @fHilite, bBoolean);
  506.     DoToField('fDimmed', @fDimmed, bBoolean);
  507.     DoToField('fSizeable', @fSizeable, bBoolean);
  508.     DoToField('fDismissesDialog', @fDismissesDialog, bBoolean);
  509.     DoToField('fAdornment', @fAdornment, bCntlAdornment);
  510.     DoToField('fPenSize', @fPenSize, bPoint);
  511.     DoToField('fInset', @fInset, bRect);
  512.     {$Push} {$H-}
  513.     TextStyleFields('fTextStyle', fTextStyle, DoToField);
  514.     {$Pop}
  515.     INHERITED Fields(DoToField);
  516.     END;
  517.  
  518. {--------------------------------------------------------------------------------------------------}
  519. {$S MAOpen}
  520.  
  521. PROCEDURE TCtlMgr.ICtlMgr(itsSuperView: TView;
  522.                           itsLocation, itsSize: VPoint;
  523.                           itsHSizeDet, itsVSizeDet: SizeDeterminer;
  524.                           itsTitle: Str255;
  525.                           itsVal, itsMin, itsMax: Longint;
  526.                           itsProcID: INTEGER);
  527.  
  528.     VAR
  529.         itsBounds:            Rect;
  530.  
  531.     BEGIN
  532.     fCMgrControl := NIL;
  533.  
  534.     { These MUST be initialized because SetLongValues tests each new value against }
  535.     { the old value before doing anything.  If the fLongMax value should happen to }
  536.     { have a (bogus - uninitialized) value that matches itsMax, fBitsToShift won't }
  537.     { be initialized and the control manager control will behave erratically. }
  538.     fBitsToShift := 0;
  539.     fLongVal := 0;
  540.     fLongMin := 0;
  541.     fLongMax := 0;
  542.  
  543.     IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  544.     WITH fSize DO
  545.         {$Push} {$H-}
  546.         SetRect(itsBounds, 0, 0, h, v);
  547.         {$Pop}
  548.     CreateCMgrControl(itsBounds, itsTitle, itsVal, itsMin, itsMax, itsProcID);
  549.     END;
  550.  
  551. {--------------------------------------------------------------------------------------------------}
  552. {$S MAOpen}
  553.  
  554. PROCEDURE TCtlMgr.IRes(itsDocument: TDocument;
  555.                        itsSuperView: TView;
  556.                        VAR itsParams: Ptr);
  557.  
  558.     BEGIN
  559.     fCMgrControl := NIL;
  560.  
  561.     { These MUST be initialized because SetLongValues tests each new value against }
  562.     { the old value before doing anything.  If the fLongMax value should happen to }
  563.     { have a (bogus - uninitialized) value that matches itsMax, fBitsToShift won't }
  564.     { be initialized and the control manager control will behave erratically. }
  565.     fBitsToShift := 0;
  566.     fLongVal := 0;
  567.     fLongMin := 0;
  568.     fLongMax := 0;
  569.  
  570.     INHERITED IRes(itsDocument, itsSuperView, itsParams);
  571.     {The subclass must create the Control Manager control}
  572.     END;
  573.  
  574. {--------------------------------------------------------------------------------------------------}
  575. {$S MAWriteRes}
  576.  
  577. PROCEDURE TCtlMgr.WriteRes(theResource: ViewRsrcHndl;
  578.                            VAR itsParams: Ptr); OVERRIDE;
  579.  
  580.     BEGIN
  581.     { We don't write TCtlMgrs… }
  582.     END;
  583.  
  584. {--------------------------------------------------------------------------------------------------}
  585. {$S MAClose}
  586.  
  587. PROCEDURE TCtlMgr.Free; OVERRIDE;
  588.  
  589.     BEGIN
  590.     IF fCMgrControl <> NIL THEN
  591.         BEGIN
  592.         SetCMgrVisibility(FALSE);                        { This insures that HideControl, which will
  593.                                                          }
  594.         { be called by SizeControl, doesn't do }
  595.         { anything.  HideControl seems to have some }
  596.         { problems with large (~> 14000x14000) }
  597.         SizeControl(fCMgrControl, 0, 0);                { Prevent CMgr from erasing the control! }
  598.         DisposeControl(fCMgrControl);
  599.         fCMgrControl := NIL;                            { So BeInPort and others will be happy! }
  600.         END;
  601.     INHERITED Free;
  602.     END;
  603.  
  604. {--------------------------------------------------------------------------------------------------}
  605. {$S MANonRes}
  606.  
  607. PROCEDURE TCtlMgr.BeInPort(itsPort: GrafPtr); OVERRIDE;
  608.  
  609.     BEGIN
  610.     IF fCMgrControl <> NIL THEN
  611.         WITH fCMgrControl^^ DO
  612.             IF itsPort = NIL THEN
  613.                 BEGIN
  614.                 SetCMgrVisibility(FALSE);
  615.                 contrlOwner := WindowPtr(gWorkPort);
  616.                 END
  617.             ELSE
  618.                 BEGIN
  619.                 SetCMgrVisibility(TRUE);
  620.                 contrlOwner := WindowPtr(itsPort);
  621.                 END;
  622.     END;
  623.  
  624. {--------------------------------------------------------------------------------------------------}
  625. {$S MAOpen}
  626.  
  627. PROCEDURE TCtlMgr.CreateCMgrControl(itsBounds: Rect;
  628.                                     itsTitle: Str255;
  629.                                     itsVal, itsMin, itsMax: Longint;
  630.                                     itsProcID: INTEGER);
  631.  
  632.     VAR
  633.         itsPort:            GrafPtr;
  634.         aCMgrControl:        ControlHandle;
  635.         fi:                 FailInfo;
  636.  
  637.     PROCEDURE HandleFailure(error: OSErr;
  638.                             message: Longint);
  639.  
  640.         BEGIN
  641.         Free;
  642.         END;
  643.  
  644.     BEGIN
  645.     itsPort := GetGrafPort;
  646.     IF itsPort = NIL THEN
  647.         itsPort := gWorkPort;
  648.     CatchFailures(fi, HandleFailure);
  649.     aCMgrControl := NewControl(itsPort, itsBounds, itsTitle, FALSE, 0, 0, 0,
  650.                                BOR(itsProcID, useWFont), Longint(SELF));
  651.     FailNIL(aCMgrControl);
  652.     Success(fi);
  653.     { Keep control off Window's control list b/c the Window Mgr adds the regions of controls in
  654.     the control list to the update region (see NOTE under DrawControls in Inside Mac volume I)
  655.     generating an update event. }
  656.     WITH WindowPeek(itsPort)^ DO
  657.         controlList := controlList^^.nextControl;
  658.  
  659.     IF fDimmed THEN
  660.         aCMgrControl^^.contrlHilite := 255;
  661.     fCMgrControl := aCMgrControl;
  662.  
  663.     SetLongValues(itsVal, itsMin, itsMax, kDontRedraw);        { Remember, the control was created
  664.     with zeros, fix it up. }
  665.  
  666.     SetCMgrVisibility(itsPort <> gWorkPort);
  667.     END;
  668.  
  669. {--------------------------------------------------------------------------------------------------}
  670. {$S MANonRes}
  671.  
  672. PROCEDURE TCtlMgr.DimState(state, redraw: BOOLEAN); OVERRIDE;
  673.  
  674.     PROCEDURE SetHilite;
  675.  
  676.         BEGIN
  677.         HiliteControl(fCMgrControl, ORD(state) * 255);
  678.         fDimmed := state;
  679.         END;
  680.  
  681.     BEGIN
  682.     IF fDimmed <> state THEN
  683.         WhileFocused(SetHilite, redraw);
  684.     END;
  685.  
  686. {--------------------------------------------------------------------------------------------------}
  687. {$S MASelCommand}
  688.  
  689. FUNCTION TCtlMgr.DoMouseCommand(VAR theMouse: Point;
  690.                                 VAR info: EventInfo;
  691.                                 VAR hysteresis: Point): TCommand; OVERRIDE;
  692.  
  693.     BEGIN
  694.     IF TestControl(fCMgrControl, theMouse) <> 0 THEN
  695.         IF TrackControl(fCMgrControl, theMouse, NIL) <> 0 THEN
  696.             DoChoice(SELF, fDefChoice);
  697.     DoMouseCommand := NIL;
  698.     END;
  699.  
  700. {--------------------------------------------------------------------------------------------------}
  701. {$S MAControlRes}
  702.  
  703. PROCEDURE TCtlMgr.Draw(area: Rect); OVERRIDE;
  704.  
  705.     VAR
  706.         savedOwner:         WindowPtr;
  707.         qdExtent:            Rect;
  708.  
  709.     BEGIN
  710.     IF IsCMgrVisible THEN
  711.         BEGIN                                            { Set the port in case we're printing }
  712.         {$IFC qDebug}
  713.         AssumeFocused;
  714.         {$ENDC}
  715.  
  716.         WITH fCMgrControl^^ DO
  717.             BEGIN
  718.             savedOwner := contrlOwner;
  719.             contrlOwner := WindowPtr(thePort);
  720.             END;
  721.     
  722.         PenNormal;                                    {NECESSARY?}
  723.  
  724.         IF qNeedsROM128K | gConfiguration.hasROM128K THEN
  725.             Draw1Control(fCMgrControl)
  726.         ELSE
  727.             BEGIN
  728.             SetCMgrVisibility(FALSE);                { Force ShowControl to redraw }
  729.             ShowControl(fCMgrControl);
  730.             END;
  731.  
  732.         fCMgrControl^^.contrlOwner := savedOwner;
  733.         END;
  734.  
  735.  
  736.     {!!! Not in 2.0
  737.     because we found we needed a IsDrawnDimmed and a IsDrawnHilited and it's too late to add them.
  738.     If you change the drawing behaviour of some ancestor you must duplicate that behaviour here
  739.     if you want it reflected in TCtlMgr and subclasses.  Will be fixed in next release. Sorry.
  740.     INHERITED Draw(area);
  741.     }
  742.  
  743.     IF fAdornment <> [] THEN
  744.         BEGIN
  745.         GetQDExtent(qdExtent);
  746.         Adorn(qdExtent, fPenSize, fAdornment);
  747.         END;
  748.  
  749.     END;
  750.  
  751. {--------------------------------------------------------------------------------------------------}
  752. {$S MAControlRes}
  753.  
  754. FUNCTION TCtlMgr.IsCMgrVisible: BOOLEAN;
  755.  
  756.     BEGIN
  757.     IsCMgrVisible := (fCMgrControl <> NIL) & (fCMgrControl^^.contrlVis = 255);
  758.     END;
  759.  
  760. {--------------------------------------------------------------------------------------------------}
  761. {$S MAControlRes}
  762.  
  763. FUNCTION TCtlMgr.GetMax: INTEGER;
  764.  
  765.     BEGIN
  766.     GetMax := GetCtlMax(fCMgrControl)
  767.     END;
  768.  
  769. {--------------------------------------------------------------------------------------------------}
  770. {$S MAControlRes}
  771.  
  772. FUNCTION TCtlMgr.GetMin: INTEGER;
  773.  
  774.     BEGIN
  775.     GetMin := GetCtlMin(fCMgrControl)
  776.     END;
  777.  
  778. {--------------------------------------------------------------------------------------------------}
  779. {$S MAControlRes}
  780.  
  781. PROCEDURE TCtlMgr.GetText(VAR theText: Str255);
  782.  
  783.     BEGIN
  784.     { theText := fCMgrControl^^.contrlTitle; }
  785.     CopyStr255(fCMgrControl^^.contrlTitle, @theText);
  786.     END;
  787.  
  788. {--------------------------------------------------------------------------------------------------}
  789. {$S MAControlRes}
  790.  
  791. FUNCTION TCtlMgr.GetVal: INTEGER;
  792.  
  793.     BEGIN
  794.     GetVal := GetCtlValue(fCMgrControl)
  795.     END;
  796.  
  797. {--------------------------------------------------------------------------------------------------}
  798. {$S MANonRes}
  799.  
  800. PROCEDURE TCtlMgr.HiliteState(state, redraw: BOOLEAN); OVERRIDE;
  801.  
  802.     PROCEDURE SetHilite;
  803.  
  804.         BEGIN
  805.         HiliteControl(fCMgrControl, ORD(state) * 10);
  806.         END;
  807.  
  808.     BEGIN
  809.     IF fHilite <> state THEN
  810.         WhileFocused(SetHilite, redraw);
  811.     fHilite := state;
  812.     END;
  813.  
  814. {--------------------------------------------------------------------------------------------------}
  815. {$S MANonRes}
  816.  
  817. PROCEDURE TCtlMgr.Resize(width, height: VCoordinate;
  818.                          invalidate: BOOLEAN); OVERRIDE;
  819.  
  820.     PROCEDURE ResizeCMgrControl;
  821.  
  822.         VAR
  823.             aRect:                Rect;
  824.  
  825.         BEGIN
  826.         WITH fInset DO
  827.             {$Push} {$H-}
  828.             SetRect(aRect, left, top, width - right, height - bottom);
  829.             {$Pop}
  830.         WITH aRect DO
  831.             BEGIN
  832.             MoveControl(fCMgrControl, left, top);
  833.             SizeControl(fCMgrControl, ABS(right - left), ABS(bottom - top));
  834.             END;
  835.         END;
  836.  
  837.     BEGIN
  838.     IF fSizeable & (fCMgrControl <> NIL) THEN
  839.         WhileFocused(ResizeCMgrControl, kDontRedraw);
  840.     INHERITED Resize(width, height, invalidate);
  841.     END;
  842.  
  843. {--------------------------------------------------------------------------------------------------}
  844. {$S MAControlRes}
  845.  
  846. PROCEDURE TCtlMgr.SetCMgrVisibility(beVisible: BOOLEAN);
  847.  
  848.     BEGIN
  849.     IF fCMgrControl <> NIL THEN
  850.         IF beVisible THEN
  851.             fCMgrControl^^.contrlVis := 255
  852.         ELSE
  853.             fCMgrControl^^.contrlVis := 0;
  854.     END;
  855.  
  856. {--------------------------------------------------------------------------------------------------}
  857. {$S MAControlRes}
  858.  
  859. PROCEDURE TCtlMgr.SetMax(itsMax: INTEGER;
  860.                          redraw: BOOLEAN);
  861.  
  862.     PROCEDURE DoSetMax;
  863.  
  864.         BEGIN
  865.         SetCtlMax(fCMgrControl, itsMax);
  866.         END;
  867.  
  868.     BEGIN
  869.     WhileFocused(DoSetMax, redraw);
  870.     END;
  871.  
  872. {--------------------------------------------------------------------------------------------------}
  873. {$S MAControlRes}
  874.  
  875. PROCEDURE TCtlMgr.SetMin(itsMin: INTEGER;
  876.                          redraw: BOOLEAN);
  877.  
  878.     PROCEDURE DoSetMin;
  879.  
  880.         BEGIN
  881.         SetCtlMin(fCMgrControl, itsMin);
  882.         END;
  883.  
  884.     BEGIN
  885.     WhileFocused(DoSetMin, redraw);
  886.     END;
  887.  
  888. {--------------------------------------------------------------------------------------------------}
  889. {$S MANonRes}
  890.  
  891. PROCEDURE TCtlMgr.SetText(itsText: Str255;
  892.                           redraw: BOOLEAN);
  893.  
  894.     VAR
  895.         currentText:        Str255;
  896.  
  897.     PROCEDURE DoSetText;
  898.  
  899.         BEGIN
  900.         GetCTitle(fCMgrControl, currentText);
  901.         IF currentText <> itsText THEN
  902.             SetCTitle(fCMgrControl, itsText);
  903.         END;
  904.  
  905.     BEGIN
  906.     WhileFocused(DoSetText, redraw);
  907.     END;
  908.  
  909. {--------------------------------------------------------------------------------------------------}
  910. {$S MAControlRes}
  911.  
  912. PROCEDURE TCtlMgr.SetVal(newVal: INTEGER;
  913.                          redraw: BOOLEAN);
  914.  
  915.     PROCEDURE DoSetVal;
  916.  
  917.         BEGIN
  918.         SetCtlValue(fCMgrControl, newVal);
  919.         END;
  920.  
  921.     BEGIN
  922.     IF GetCtlValue(fCMgrControl) <> newVal THEN
  923.         WhileFocused(DoSetVal, redraw);
  924.     END;
  925.  
  926. {--------------------------------------------------------------------------------------------------}
  927. {$S MAControlRes}
  928.  
  929. PROCEDURE TCtlMgr.SetValues(itsVal, itsMin, itsMax: INTEGER;
  930.                             redraw: BOOLEAN);
  931.  
  932.     PROCEDURE DoSetValues;
  933.  
  934.         BEGIN
  935.         SetCtlMin(fCMgrControl, itsMin);
  936.         SetCtlMax(fCMgrControl, itsMax);
  937.         SetCtlValue(fCMgrControl, itsVal);
  938.         END;
  939.  
  940.     BEGIN
  941.     WhileFocused(DoSetValues, redraw);
  942.     END;
  943.  
  944. {--------------------------------------------------------------------------------------------------}
  945. {$S MAControlRes}
  946.  
  947. PROCEDURE TCtlMgr.WhileFocused(PROCEDURE DoToControl;
  948.                                redraw: BOOLEAN);
  949.  
  950.     VAR
  951.         savedFocusedView:    TView;
  952.         wasVisible:         BOOLEAN;
  953.  
  954.     BEGIN
  955.     IF fCMgrControl <> NIL THEN
  956.         BEGIN
  957.         IF redraw & Focus THEN
  958.             DoToControl
  959.         ELSE
  960.             BEGIN
  961.             wasVisible := IsCMgrVisible;
  962.             SetCMgrVisibility(FALSE);
  963.             DoToControl;
  964.             IF wasVisible & (NOT IsCMgrVisible)         { If DoToControl didn't set it }
  965.                THEN
  966.                 SetCMgrVisibility(wasVisible);            { …restore visibility }
  967.             END;
  968.         END;
  969.     END;
  970.  
  971. {--------------------------------------------------------------------------------------------------}
  972. {$S MAControlRes}
  973.  
  974. FUNCTION TCtlMgr.GetLongMax: VCoordinate;
  975.  
  976.     BEGIN
  977.     GetLongMax := fLongMax;
  978.     END;
  979.  
  980. {--------------------------------------------------------------------------------------------------}
  981. {$S MAControlRes}
  982.  
  983. FUNCTION TCtlMgr.GetLongMin: VCoordinate;
  984.  
  985.     BEGIN
  986.     GetLongMin := fLongMin;
  987.     END;
  988.  
  989. {--------------------------------------------------------------------------------------------------}
  990. {$S MAControlRes}
  991.  
  992. FUNCTION TCtlMgr.GetLongVal: VCoordinate;
  993.  
  994.     BEGIN
  995.     GetLongVal := fLongVal;
  996.     END;
  997.  
  998. {--------------------------------------------------------------------------------------------------}
  999. {$S MAControlRes}
  1000.  
  1001. PROCEDURE TCtlMgr.SetLongMax(itsMax: VCoordinate;
  1002.                                 redraw: BOOLEAN);
  1003.  
  1004.     BEGIN
  1005.     IF itsMax <> fLongMax THEN
  1006.         BEGIN
  1007.         fLongMax := itsMax;
  1008.         fBitsToShift := 0;
  1009.         WHILE itsMax > MAXINT DO
  1010.             BEGIN
  1011.             itsMax := BSR(itsMax, 1);
  1012.             fBitsToShift := fBitsToShift + 1;
  1013.             END;
  1014.         SetMax(itsMax, redraw);
  1015.         END;
  1016.     END;
  1017.  
  1018. {--------------------------------------------------------------------------------------------------}
  1019. {$S MAControlRes}
  1020.  
  1021. PROCEDURE TCtlMgr.SetLongMin(itsMin: VCoordinate;
  1022.                                 redraw: BOOLEAN);
  1023.  
  1024.     BEGIN
  1025.     IF itsMin <> fLongMin THEN
  1026.         BEGIN
  1027.         fLongMin := itsMin;
  1028.         SetMin(BSR(itsMin, fBitsToShift), redraw);
  1029.         END;
  1030.     END;
  1031.  
  1032. {--------------------------------------------------------------------------------------------------}
  1033. {$S MAControlRes}
  1034.  
  1035. PROCEDURE TCtlMgr.SetLongVal(itsVal: VCoordinate;
  1036.                                 redraw: BOOLEAN);
  1037.  
  1038.     BEGIN
  1039.     itsVal := Max(fLongMin, Min(itsVal, fLongMax));
  1040.     IF itsVal <> fLongVal THEN
  1041.         BEGIN
  1042.         fLongVal := itsVal;
  1043.         SetVal(BSR(itsVal, fBitsToShift), redraw);
  1044.         END;
  1045.     END;
  1046.  
  1047. {--------------------------------------------------------------------------------------------------}
  1048. {$S MAControlRes}
  1049.  
  1050. PROCEDURE TCtlMgr.SetLongValues(itsVal, itsMin, itsMax: VCoordinate;
  1051.                                    redraw: BOOLEAN);
  1052.  
  1053.     BEGIN
  1054.     SetLongMax(itsMax, redraw);            { Must be first to get fBitsToShift setup }
  1055.     SetLongMin(itsMin, redraw);
  1056.     SetLongVal(itsVal, redraw);
  1057.     END;
  1058.  
  1059. {--------------------------------------------------------------------------------------------------}
  1060. {$S MAFields}
  1061.  
  1062. PROCEDURE TCtlMgr.Fields(PROCEDURE DoToField(fieldName: Str255;
  1063.                                              fieldAddr: Ptr;
  1064.                                              fieldType: INTEGER)); OVERRIDE;
  1065.  
  1066.     BEGIN
  1067.     DoToField('TCtlMgr', NIL, bClass);
  1068.     DoToField('fCMgrControl', @fCMgrControl, bControlHandle);
  1069.     DoToField('fBitsToShift', @fBitsToShift, bInteger);
  1070.     DoToField('fLongVal', @fLongVal, bLongInt);
  1071.     DoToField('fLongMin', @fLongMin, bLongInt);
  1072.     DoToField('fLongMax', @fLongMax, bLongInt);
  1073.     INHERITED Fields(DoToField);
  1074.     END;
  1075.  
  1076. {--------------------------------------------------------------------------------------------------}
  1077. {$S MAOpen}
  1078.  
  1079. PROCEDURE TScrollBar.IScrollBar(itsSuperView: TView;
  1080.                                 itsLocation, itsSize: VPoint;
  1081.                                 itsHSizeDet, itsVSizeDet: SizeDeterminer;
  1082.                                 itsDirection: VHSelect;
  1083.                                 itsVal, itsMin, itsMax: Longint);
  1084.  
  1085.     BEGIN
  1086.     ICtlMgr(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, '', itsVal, itsMin,
  1087.             itsMax, scrollBarProc);
  1088.     fDirection := itsDirection;
  1089.  
  1090.     IF itsDirection = h THEN
  1091.         fDefChoice := mHScrollBarHit
  1092.     ELSE
  1093.         fDefChoice := mVScrollBarHit;
  1094.     END;
  1095.  
  1096. {--------------------------------------------------------------------------------------------------}
  1097. {$S MAOpen}
  1098.  
  1099. PROCEDURE TScrollBar.IRes(itsDocument: TDocument;
  1100.                           itsSuperView: TView;
  1101.                           VAR itsParams: Ptr); OVERRIDE;
  1102.  
  1103.     VAR
  1104.         area:                Rect;
  1105.  
  1106.     BEGIN
  1107.     INHERITED IRes(itsDocument, itsSuperView, itsParams);
  1108.  
  1109.     ControlArea(area);
  1110.     WITH ScrollBarTemplatePtr(itsParams)^ DO
  1111.         CreateCMgrControl(area, '', value, minimum, maximum, scrollBarProc);
  1112.  
  1113.     WITH area DO
  1114.         IF (bottom - top) >= (right - left) THEN
  1115.             BEGIN
  1116.             fDirection := v;
  1117.             fDefChoice := mVScrollBarHit;
  1118.             END
  1119.         ELSE
  1120.             BEGIN
  1121.             fDirection := h;
  1122.             fDefChoice := mHScrollBarHit;
  1123.             END;
  1124.  
  1125.     OffsetPtr(itsParams, SIZEOF(ScrollBarTemplate));
  1126.     END;
  1127.  
  1128. {--------------------------------------------------------------------------------------------------}
  1129. {$S MAWriteRes}
  1130.  
  1131. PROCEDURE TScrollBar.WRes(theResource: ViewRsrcHndl;
  1132.                           VAR itsParams: Ptr); OVERRIDE;
  1133.  
  1134.     VAR
  1135.         sbPtr:                ScrollBarTemplatePtr;
  1136.  
  1137.     BEGIN
  1138.     INHERITED WRes(theResource, itsParams);
  1139.  
  1140.     sbPtr := ScrollBarTemplatePtr(ExpandPtr(theResource, itsParams, SIZEOF(ScrollBarTemplate)));
  1141.  
  1142.     WITH sbPtr^ DO
  1143.         BEGIN
  1144.         value := fLongVal;
  1145.         minimum := fLongMin;
  1146.         maximum := fLongMax;
  1147.         END;
  1148.     END;
  1149.  
  1150. {--------------------------------------------------------------------------------------------------}
  1151. {$S MAWriteRes}
  1152.  
  1153. PROCEDURE TScrollBar.WriteRes(theResource: ViewRsrcHndl;
  1154.                               VAR itsParams: Ptr); OVERRIDE;
  1155.  
  1156.     BEGIN
  1157.     gWResSignature := 'sbar'; gWResType := 'TScrollBar';
  1158.     WRes(theResource, itsParams);
  1159.     END;
  1160.  
  1161. {--------------------------------------------------------------------------------------------------}
  1162. {$S MAControlRes}
  1163.  
  1164. PROCEDURE TScrollBar.ActionProc(partCode: INTEGER);
  1165.  
  1166.     VAR
  1167.         backwards:            BOOLEAN;
  1168.  
  1169.     BEGIN
  1170.     IF partCode <> 0 THEN
  1171.         BEGIN
  1172.         backwards := (partCode = inUpButton) | (partCode = inPageUp);
  1173.  
  1174.         IF (backwards & (fLongVal > fLongMin)) | ((NOT backwards) & (fLongVal < fLongMax)) THEN
  1175.             TrackScrollBar(partCode);
  1176.  
  1177.         Update;    { Make sure that we're in synch before returning ??? How can this be controlable?}
  1178.         IF Focus THEN; { make sure i am looking at myself… e.e. cummings }
  1179.         END;
  1180.     END;
  1181.  
  1182. {--------------------------------------------------------------------------------------------------}
  1183. {$S MAScroll}
  1184.  
  1185. PROCEDURE TScrollBar.DeltaValue(delta: VCoordinate);
  1186.  
  1187.     BEGIN
  1188.     IF delta <> 0 THEN
  1189.         BEGIN
  1190.         {Ensure that delta does not cause an overflow (or underflow)}
  1191.         IF delta > 0 THEN
  1192.             delta := Min(delta, fLongMax - fLongVal)
  1193.         ELSE
  1194.             delta := Max(delta, fLongMin - fLongVal);
  1195.  
  1196.         SetLongVal(fLongVal + delta, TRUE);
  1197.         END;
  1198.     END;
  1199.  
  1200. {--------------------------------------------------------------------------------------------------}
  1201. {$S MAScroll}
  1202.  
  1203. FUNCTION TScrollBar.DoMouseCommand(VAR theMouse: Point;
  1204.                                    VAR info: EventInfo;
  1205.                                    VAR hysteresis: Point): TCommand; OVERRIDE;
  1206.  
  1207.     VAR
  1208.         partCode:            INTEGER;
  1209.         oldLongValue:        VCoordinate;
  1210.         newLongValue:        VCoordinate;
  1211.  
  1212.     BEGIN
  1213.     {$IFC qDebug}
  1214.     AssumeFocused;
  1215.     {$ENDC}
  1216.  
  1217.     oldLongValue := fLongVal;
  1218.  
  1219.     CASE TestControl(fCMgrControl, theMouse) OF
  1220.         inUpButton, inDownButton, inPageUp, inPageDown:
  1221.             BEGIN
  1222.             partCode := TrackControl(fCMgrControl, theMouse, @ActionProcForTScrollBar);
  1223.  
  1224.             { This method MUST inform its superview of the change!
  1225.             Thanks to GLB! }
  1226.             IF fLongVal <> oldLongValue THEN
  1227.                 DoChoice(SELF, fDefChoice);
  1228.             END;
  1229.         inThumb:
  1230.             IF TrackControl(fCMgrControl, theMouse, NIL) = inThumb THEN
  1231.                 BEGIN
  1232.                 {If thumb is dragged to bottom of scroll bar then ensure that
  1233.                 the new long value is set to the maximum long value.
  1234.  
  1235.                 We get killed by side effects if we don't use a temporary variable here.
  1236.                 This doesn't show up in the TSScrollBar class because this code is
  1237.                 overridden, but it will show up in derived classes that depend on this
  1238.                 code }
  1239.                 IF GetVal = GetMax THEN
  1240.                     newLongValue := fLongMax
  1241.                 ELSE
  1242.                     BEGIN
  1243.                     newLongValue := BSL(Longint(GetVal), fBitsToShift);
  1244.                     END;
  1245.  
  1246.                 SetLongVal(newLongValue, kRedraw);
  1247.  
  1248.                 { This method MUST inform its superview of the change! }
  1249.                 IF fLongVal <> oldLongValue THEN
  1250.                     DoChoice(SELF, fDefChoice);
  1251.                 END;
  1252.     END;
  1253.     DoMouseCommand := NIL;
  1254.     END;
  1255.  
  1256. {--------------------------------------------------------------------------------------------------}
  1257. {$S MAControlRes}
  1258.  
  1259. PROCEDURE TScrollBar.TrackScrollBar(partCode: INTEGER);
  1260.  
  1261.     BEGIN
  1262.     IF (partCode = inPageUp) | (partCode = inUpButton) THEN
  1263.         DeltaValue( - 1)
  1264.     ELSE
  1265.         DeltaValue(1);
  1266.     END;
  1267.  
  1268. {--------------------------------------------------------------------------------------------------}
  1269. {$S MAFields}
  1270.  
  1271. PROCEDURE TScrollBar.Fields(PROCEDURE DoToField(fieldName: Str255;
  1272.                                                 fieldAddr: Ptr;
  1273.                                                 fieldType: INTEGER)); OVERRIDE;
  1274.  
  1275.     BEGIN
  1276.     DoToField('TScrollBar', NIL, bClass);
  1277.     DoToField('fDirection', @fDirection, bVHSelect);
  1278.     INHERITED Fields(DoToField);
  1279.     END;
  1280.  
  1281. {--------------------------------------------------------------------------------------------------}
  1282. {$S MAOpen}
  1283.  
  1284. PROCEDURE TSScrollBar.ISScrollBar(itsSuperView: TView;
  1285.                                   itsLocation, itsSize: VPoint;
  1286.                                   itsHSizeDet, itsVSizeDet: SizeDeterminer;
  1287.                                   itsDirection: VHSelect;
  1288.                                   itsMax: Longint;
  1289.                                   itsScroller: TScroller);
  1290.  
  1291.     VAR
  1292.         itsWindow:            TWindow;
  1293.         fi:                 FailInfo;
  1294.  
  1295.     PROCEDURE HandleFailure(error: OSErr;
  1296.                             message: Longint);
  1297.  
  1298.         BEGIN
  1299.         Free;
  1300.         END;
  1301.  
  1302.     BEGIN
  1303.     fScrollers := NIL;
  1304.     IScrollBar(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsDirection, 0, 0,
  1305.                itsMax);
  1306.     itsWindow := GetWindow;
  1307.     SetCMgrVisibility((itsWindow <> NIL) & itsWindow.fIsActive);
  1308.  
  1309.     CatchFailures(fi, HandleFailure);
  1310.     fScrollers := NewList;
  1311.     {$IFC qDebug}
  1312.     fScrollers.SetEltType('TScroller');
  1313.     {$ENDC}
  1314.     AttachScroller(itsScroller);
  1315.     Success(fi);
  1316.     END;
  1317.  
  1318. {--------------------------------------------------------------------------------------------------}
  1319. {$S MAOpen}
  1320.  
  1321. PROCEDURE TSScrollBar.IRes(itsDocument: TDocument;
  1322.                            itsSuperView: TView;
  1323.                            VAR itsParams: Ptr); OVERRIDE;
  1324.  
  1325.     VAR
  1326.         itsWindow:            TWindow;
  1327.         fi:                 FailInfo;
  1328.  
  1329.     PROCEDURE HandleFailure(error: OSErr;
  1330.                             message: Longint);
  1331.  
  1332.         BEGIN
  1333.         Free;
  1334.         END;
  1335.  
  1336.     BEGIN
  1337.     INHERITED IRes(itsDocument, itsSuperView, itsParams);
  1338.     itsWindow := GetWindow;
  1339.     SetCMgrVisibility((itsWindow <> NIL) & itsWindow.fIsActive);
  1340.  
  1341.     CatchFailures(fi, HandleFailure);
  1342.     fScrollers := NewList;
  1343.     {$IFC qDebug}
  1344.     fScrollers.SetEltType('TScroller');
  1345.     {$ENDC}
  1346.     Success(fi);
  1347.     END;
  1348.  
  1349. {--------------------------------------------------------------------------------------------------}
  1350. {$S MAWriteRes}
  1351.  
  1352. PROCEDURE TSScrollBar.WriteRes(theResource: ViewRsrcHndl;
  1353.                                VAR itsParams: Ptr); OVERRIDE;
  1354.  
  1355.     BEGIN
  1356.     { We never want to write TSScrollbars.    TScroller will create its own }
  1357.     END;
  1358.  
  1359. {--------------------------------------------------------------------------------------------------}
  1360. {$S MAClose}
  1361.  
  1362. PROCEDURE TSScrollBar.Free; OVERRIDE;
  1363.  
  1364.     PROCEDURE DetachFromScroller(theScroller: TScroller);
  1365.  
  1366.         BEGIN
  1367.         IF theScroller.fScrollBars[fDirection] = SELF THEN
  1368.             theScroller.HaveScrollBar(NIL, fDirection);
  1369.         END;
  1370.  
  1371.     BEGIN
  1372.     IF fScrollers <> NIL THEN
  1373.         fScrollers.Each(DetachFromScroller);
  1374.     FreeIfObject(fScrollers);
  1375.     fScrollers := NIL;
  1376.  
  1377.     INHERITED Free;
  1378.     END;
  1379.  
  1380. {--------------------------------------------------------------------------------------------------}
  1381. {$S MAActivate}
  1382.  
  1383. PROCEDURE TSScrollBar.Activate(entering: BOOLEAN); OVERRIDE;
  1384.  
  1385.     PROCEDURE SetScrollBar;
  1386.  
  1387.         VAR
  1388.             itsRect:            Rect;
  1389.  
  1390.         BEGIN
  1391.         itsRect := fCMgrControl^^.contrlRect;
  1392.         IF entering THEN
  1393.             ShowControl(fCMgrControl)
  1394.         ELSE
  1395.             BEGIN
  1396.             HideControl(fCMgrControl);
  1397.             { Thanks Larry 11/2/89 }
  1398.             IF IsFocused THEN
  1399.                 Draw(itsRect);                            { Get the frame drawn. }
  1400.             END;
  1401.         IF IsFocused THEN
  1402.             ValidRect(itsRect);                         { Because Control Manager invalidates it. }
  1403.         END;
  1404.  
  1405.     BEGIN
  1406.     WhileFocused(SetScrollBar, Focus);
  1407.     END;
  1408.  
  1409. {--------------------------------------------------------------------------------------------------}
  1410. {$S MAOpen}
  1411.  
  1412. PROCEDURE TSScrollBar.AttachScroller(itsScroller: TScroller);
  1413.  
  1414.     BEGIN
  1415.     IF itsScroller <> NIL THEN
  1416.         BEGIN
  1417.         fScrollers.Insert(itsScroller);
  1418.         itsScroller.HaveScrollBar(SELF, fDirection);
  1419.         END;
  1420.     END;
  1421.  
  1422. {--------------------------------------------------------------------------------------------------}
  1423. {$S MANonRes}
  1424.  
  1425. PROCEDURE TSScrollBar.BeInPort(itsPort: GrafPtr); OVERRIDE;
  1426.  
  1427.     VAR
  1428.         itsWindow:            TWindow;
  1429.  
  1430.     BEGIN
  1431.     INHERITED BeInPort(itsPort);
  1432.     itsWindow := GetWindow;
  1433.     SetCMgrVisibility((itsWindow <> NIL) & itsWindow.fIsActive);
  1434.     END;
  1435.  
  1436. {--------------------------------------------------------------------------------------------------}
  1437. {$S MAScroll}
  1438.  
  1439. FUNCTION TSScrollBar.DoMouseCommand(VAR theMouse: Point;
  1440.                                     VAR info: EventInfo;
  1441.                                     VAR hysteresis: Point): TCommand; OVERRIDE;
  1442.  
  1443.     VAR
  1444.         partCode:            INTEGER;
  1445.         sBarDelta:            Longint;
  1446.  
  1447.     PROCEDURE ScrollToThumb(theView: TScroller);
  1448.  
  1449.         BEGIN
  1450.         sBarDelta := sBarDelta + theView.ScrollRelative(fDirection, fLongVal);
  1451.         END;
  1452.  
  1453.     BEGIN
  1454.     {$IFC qDebug}
  1455.     AssumeFocused;
  1456.     {$ENDC}
  1457.  
  1458.     GetFocus(gSaveFocusRec);
  1459.     IF TestControl(fCMgrControl, theMouse) = inThumb THEN
  1460.         BEGIN
  1461.         IF TrackControl(fCMgrControl, theMouse, NIL) = inThumb THEN
  1462.             BEGIN
  1463.             sBarDelta := 0;
  1464.             {If thumb is dragged to bottom of scroll bar then ensure that
  1465.              the new long value is set to the maximum long value.}
  1466.             IF GetVal = GetMax THEN
  1467.                 fLongVal := fLongMax
  1468.             ELSE
  1469.                 fLongVal := BSL(GetVal, fBitsToShift);
  1470.             fScrollers.Each(ScrollToThumb);
  1471.             SetFocus(gSaveFocusRec);
  1472.             IF sBarDelta <> 0 THEN
  1473.                 SetLongVal(fLongVal + sBarDelta, kRedraw);
  1474.             END;
  1475.         DoMouseCommand := NIL;
  1476.         END
  1477.     ELSE
  1478.         DoMouseCommand := INHERITED DoMouseCommand(theMouse, info, hysteresis);
  1479.     END;
  1480.  
  1481. {--------------------------------------------------------------------------------------------------}
  1482. {$S MAControlRes}
  1483.  
  1484. PROCEDURE TSScrollBar.Draw(area: Rect); OVERRIDE;
  1485.  
  1486.     VAR
  1487.         itsRect:            Rect;
  1488.  
  1489.     BEGIN
  1490.     {$IFC qDebug}
  1491.     AssumeFocused;
  1492.     {$ENDC}
  1493.  
  1494.     IF NOT IsCMgrVisible THEN
  1495.         BEGIN
  1496.         PenNormal;
  1497.         itsRect := fCMgrControl^^.contrlRect;
  1498.         FrameRect(itsRect);
  1499.         END;
  1500.  
  1501.     INHERITED Draw(area);
  1502.     END;
  1503.  
  1504. {--------------------------------------------------------------------------------------------------}
  1505. {$S MAScroll}
  1506.  
  1507. PROCEDURE TSScrollBar.TrackScrollBar(partCode: INTEGER);
  1508.  
  1509.     VAR
  1510.         sBarDelta:            Longint;
  1511.  
  1512.     PROCEDURE ScrollView(theScroller: TScroller);
  1513.  
  1514.         BEGIN
  1515.         sBarDelta := sBarDelta + theScroller.ScrollStep(fDirection, partCode);
  1516.         END;
  1517.  
  1518.     BEGIN
  1519.     sBarDelta := 0;
  1520.     fScrollers.Each(ScrollView);
  1521.     SetFocus(gSaveFocusRec);                            { gSaveFocusRec was set by DoMouseCommand }
  1522.     DeltaValue(sBarDelta);
  1523.     END;
  1524.  
  1525. {--------------------------------------------------------------------------------------------------}
  1526. {$S MAFields}
  1527.  
  1528. PROCEDURE TSScrollBar.Fields(PROCEDURE DoToField(fieldName: Str255;
  1529.                                                  fieldAddr: Ptr;
  1530.                                                  fieldType: INTEGER)); OVERRIDE;
  1531.  
  1532.     BEGIN
  1533.     DoToField('TSScrollBar', NIL, bClass);
  1534.     DoToField('fScrollers', @fScrollers, bObject);
  1535.     INHERITED Fields(DoToField);
  1536.     END;
  1537.